#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=3005;
int n,q,p;
int a[N];
int s[N],len;
void exgcd(int a,int b,int& x,int& y){
    if(b==0){
        x=1;y=0;
        return;
    }
    exgcd(b,a%b,y,x);
    y-=a/b*x;
}
int main(){
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    cin>>n>>q>>p;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        if(i!=1&&a[i]!=a[i-1]){
            s[a[i-1]]+=len*(len+1)/2;
            len=1;
        }
        else{
            ++len;
        }
    }
    s[a[n]]+=len*(len+1)/2;
    while(q--){
        int op,x;
        cin>>op>>x;
        ll ans=0;
        if(op==1){
            for(int i=0;i<p;++i){
                for(int j=1;j<=n;++j){
                    for(int k=j;k<=n;++k){
                        int len=k-j+1;
                        bool fl=1;
                        for(int t=1;t<=len;++t){
                            if((x*a[j+t-1]+i)%p!=a[j+len-t]){
                                fl=0;
                                break;
                            }
                        }
                        ans+=fl;
                    }
                }
            }
        }
        else{
            for(int i=0;i<p;++i){
                for(int j=1;j<=n;++j){
                    for(int k=j;k<=n;++k){
                        int len=k-j+1;
                        bool fl=1;
                        for(int t=1;t<=len;++t){
                            if((i*a[j+t-1]+x)%p!=a[j+len-t]){
                                fl=0;
                                break;
                            }
                        }
                        ans+=fl;
                    }
                }
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}